﻿using LPY.LeHealth.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace LPY.LeHealth.DAL
{
    using ServiceStack.OrmLite;
    public class CityDal:GenericBaseDAL<City>
    {
         /// <summary>
         /// 城市信息
         /// </summary>
         /// <returns></returns>
         public List<City> getcityTop7(int num)
         {
             using (var cnn = DbConnection)
             {
                 var sql = cnn.From<City>()
                     .Take(num);
                     
                 return cnn.Select(sql);
             }
          
         }
         /// <summary>
         /// 城市信息
         /// </summary>
         /// <returns></returns>
         public List<City> getcity()
         {
             using (var cnn = DbConnection)
             {
                 var sql = cnn.From<City>();
                     
                 return cnn.Select(sql);
             }

         }

         /// <summary>
         /// 获取地址名称
         /// </summary>
         /// <param name="Id"></param>
         /// <returns></returns>
         public  List<City> getName(int Id)
         { 
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=szy1021;Integrated Security=True");
             con.Open();
             string sql = "select Name from t_city where id='"+Id+"'";
             SqlCommand com = new SqlCommand(sql, con);
             SqlDataAdapter ad = new SqlDataAdapter(com);
             DataTable dt = new DataTable();
             ad.Fill(dt);
             List<City> list = new List<City>();

             foreach (DataRow i in dt.Rows)
             {
                 City city = new City();
                
                 city.Name = i["Name"].ToString();
                 list.Add(city);
             }

             return list;
         }
        /// <summary>
        /// 根据城市ID查找对应的区
        /// </summary>
        /// <returns></returns>
         public List<Region> SelRegion(int CityId)
         { 
            using(var cnn=DbConnection)
            {
                var sql=cnn.From<Region>().Where(m=>m.CityId==CityId);
                return cnn.Select<Region>(sql);
            }
         }

    }
}
